import { createRouter, createWebHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: () => import('@/views/Login/index.vue'),
      meta: { title: '登录' }
    },
    {
      path: '/',
      component: () => import('@/views/Layout/index.vue'),
      redirect: '/home',
      children: [
        {
          path: '/home',
          component: () => import('@/views/Home/index.vue'),
          meta: { title: '电子地图' }
        },
        {
          path: '/detail',
          component: () => import('@/views/Detail/index.vue'),
          meta: { title: '英雄事迹连载' }
        },
        {
          path: '/movie',
          component: () => import('@/views/Movie/index.vue'),
          meta: { title: '红色电影展播' }
        },
        {
          path: '/education',
          component: () => import('@/views/Education/index.vue'),
          meta: { title: '红色教育' }
        }
      ]
    }
  ]
})
router.beforeEach((to) => {
  NProgress.start()
})
router.afterEach((to) => {
  document.title = `${to.meta.title || ''}-英雄事迹纪念`
  NProgress.done()
})

export default router
